﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace RecruitmentProcessSystem
{
    public partial class frmCreateInterview : Form
    {
        String conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
        SqlConnection conn;
        SqlCommand cmd, cmd_add, cmd_edit;
        SqlDataAdapter da,da1,da2;
        DataSet ds,ds1,ds2;
        public frmCreateInterview()
        {
            InitializeComponent();
        }

        public void frmCreateInterview_Load(object sender, EventArgs e)
        {
            ds = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd = new SqlCommand("Select * from Nhanvien where not role = 'admin'", conn);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Interviewer");
            cboInterviewer.DataSource = ds.Tables[0];
            cboInterviewer.DisplayMember = "tennv";
            conn.Close();

            ds1 = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd_add = new SqlCommand("Select * from Applicant", conn);
            da1 = new SqlDataAdapter(cmd_add);
            da1.Fill(ds1, "Applicant---");
            cboApp.DataSource = ds1.Tables[0];
            cboApp.DisplayMember = "aname";
            conn.Close();

            ds2 = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd_edit = new SqlCommand("Select * from Vacancy", conn);
            da2 = new SqlDataAdapter(cmd_edit);
            da2.Fill(ds2, "Vacancy---");
            cboVacancy.DataSource = ds2.Tables[0];
            cboVacancy.DisplayMember = "vname";
            conn.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            conn = new SqlConnection(conStr);
            conn.Open();
            String time = dtpDate.Value.ToString();
            String interviewer = cboInterviewer.Text;
            String applicant = cboApp.Text;
            String vacancy = cboVacancy.Text;
            cmd_add = new SqlCommand("insert into Interview(idate,interviewer,aname,vname,istatus) values('" + time + "','" + interviewer + "','" + applicant + "','" + vacancy+ "','" + txtStatus.Text + "')", conn);
            cmd_add.ExecuteNonQuery();
            conn.Close();
            MessageBox.Show("Creat new successfully!");
            this.Hide();
            frmInterviewManager frmIM = new frmInterviewManager();
            //frmIM.frmInterviewManager_Load(sender, e);
            frmIM.ShowDialog();
            this.Close();
        }

        private void btnCance_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnAddInterview_Click(object sender, EventArgs e)
        {

        }

        private void btnAddApplicant_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
            frmApplicantManager frmApp = new frmApplicantManager("yes");
            frmApp.ShowDialog();
            this.Dispose();
        }
    }
}
